import django
import sys
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)

try:
    from public import setting_overrides

    settings_path = 'public.setting_overrides'
except ImportError:
    settings_path = 'public.settings'

os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_path)
django.setup()

from apps.coupon.models import Generator
import random


def generate_random_code():
    words = '23456789abcdefghjkmnpqrstuvwxyz'
    return ''.join(random.sample(words, 6))


key = input('Please input key: ')
number = input('Please input number: ')

key = key.strip()
number = int(number.strip())

for idx in range(number):
    code = generate_random_code()
    Generator.objects.create(key=key, code=code)
    print(f'第{idx + 1}个: ', code)
